package cst.a526whx.mystartpro526whx;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a526whx.mystartpro526whx.bean.WeatherInfo;
import cst.a526whx.mystartpro526whx.listener.WeatherListener;
import cst.a526whx.mystartpro526whx.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements WeatherListener,View.OnClickListener{
    private EditText cityNOInput;
    private TextView tv_cityname;
    private Button btn_find1;
    private Button btn_find2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init(){
        cityNOInput = (EditText) findViewById(R.id.editText);
        btn_find1 = (Button)findViewById(R.id.button2);
        btn_find2 = (Button)findViewById(R.id.button3);
        tv_cityname=(TextView)findViewById(R.id.tv_cityname);
        btn_find1.setOnClickListener(this);
    };
    @Override
    public void onResponse(WeatherInfo weather) {
        if(weather!=null){
            tv_cityname.setText(weather.getCity());
        }
        else {
            tv_cityname.setText("未知");
        }
    }

    @Override
    public void onFail(String msg) {
        tv_cityname.setText("失败");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button2:
                WeatherModel weatherModel=new WeatherModel();
                weatherModel.getWeather(cityNOInput.getText().toString(),this);
                break;
            case R.id.button3:
                break;
            default:
                break;
        }
    }
}
